URL = "http://apache.xl-mirror.nl//xerces/c/3/sources/xerces-c-%(VERSION)s.tar.gz"
VERSIONS = ["3.1.1"]
DEFAULT_VERSION = "3.1.1"

from source.builders import ConfigureMakeBuilder, VisualStudioBuilder
import os

class XercescWindowsBuilder( VisualStudioBuilder ):

  def make(self):
    os.chdir( self.extractedpath )

    # Buildext supports VC9
    slndir = "projects\\Win32\\VC9\\xerces-all"
    slnfile = "xerces-all.sln"
    os.chdir( slndir )
    
    # Convert to 64 bits if necessary
    replacements = []
    if self.machine.bits == 64:
      self.convertSolutionTo64(slnfile)      
      replacements += self.getx64replacements()
      replacements.append(( "^				TargetMachine=\"1\"", "TargetMachine=\"17\""))
    self.replaceLinesInFile( slnfile, replacements )

    debug = {0: "Release", 1: "Debug"}[self.debug]
    self.execute( "devenv.com " + slnfile + " /Build "+debug )
    
  def install(self):
    os.chdir( self.extractedpath )
    self.copydir( "src/xercesc", self.targetpath()+"/include/xercesc" )

    os.chdir( self.extractedpath + "/Build/Win32/VC9" )
    config = {0: "Release", 1: "Debug"}[self.debug]
    self.copypattern( config, "(.*).exe", self.targetpath()+"/bin" )
    self.copypattern( config, "(.*).dll", self.targetpath()+"/bin" )
    self.copypattern( config, "(.*).lib", self.targetpath()+"/lib" )

def decider( machine, dirs ):
  return { "Linux" : ConfigureMakeBuilder,
           "Windows" : XercescWindowsBuilder }[machine.platform]

BUILDER = decider


